package xworker.swt.dataObject.bind.values;

import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.dataObject.DataObject;
import xworker.swt.dataObject.bind.Value;

public class ThingValue implements Value {
    Thing thing;

    public ThingValue(Thing thing){
        this.thing = thing;
    }

    @Override
    public Object getValue(Object value, DataObject dataObject, ActionContext actionContext) {
        return thing.doAction("getValue", actionContext, "dataObject", dataObject);
    }

    public static ThingValue create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        return new ThingValue(self);
    }

    public static Object getValue(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        DataObject dataObject = actionContext.getObject("dataObject");
        String attributeName = self.doAction("getAttributeName", actionContext);

        return dataObject.get(attributeName);
    }
}
